import { propTypes } from "/@/utils/propTypes"
import { PropType } from "vue"

export interface GoodsState {
  id: string
  // 是否更新
  isUpdate: boolean
  specList: Spec[]
  skuList: Sku[]
  name?: string
  detailContent: string | undefined
  recommandStatus?: string
  goodsNo?: string
  stockAlarm?: number
  unit?: string
  weight?: number
  newStatus?: string
  saleNumber?: number
  sortNo?: number
  price?: string
  costPrice?: string
  status?: string
  minBuy?: number
  goodsTypes?: string[]
  multiSpec?: boolean
  categoryName?: string
  categoryId?: string
  attributeList?: any[]
}

export const SpecProps = {
  isUpdate: propTypes.bool.def(false),
  spec: {
    type: [Object] as PropType<Spec>,
    default: [],
  },
  skuList: {
    type: [Array] as PropType<Sku[]>,
    default: [],
  },
}

export const SelectAttributeProps = {
  isUpdate: propTypes.bool.def(false),
  selectItem: {
    type: [Object] as PropType<any>,
    default: [],
  },
  attributeOptions: {
    type: [Array] as PropType<any[]>,
    default: [],
  },
}

export const GoodsProps = {
  isUpdate: {
    type: Boolean,
    default: false,
  },
  specList: {
    type: [Array] as PropType<Spec[]>,
    default: [],
  },
  skuList: {
    type: [Array] as PropType<Sku[]>,
    default: [],
  },
  name: propTypes.string,
  images: propTypes.string,
  detailContent: propTypes.string,
  recommandStatus: propTypes.string,
  goodsNo: propTypes.string,
  stockAlarm: propTypes.number,
  unit: propTypes.string,
  weight: propTypes.number,
  newStatus: propTypes.string,
  sortNo: propTypes.number,
  price: propTypes.oneOfType([propTypes.string, propTypes.number]),
  // 划线价
  linePrice: propTypes.oneOfType([propTypes.string, propTypes.number]),
  // 成本价
  costPrice: propTypes.oneOfType([propTypes.string, propTypes.number]),
  // 包装费
  bagPrice: propTypes.oneOfType([propTypes.string, propTypes.number]),
  status: propTypes.string,
  minBuy: propTypes.number,
  // 商品类型
  goodsTypes: {
    type: [Array] as PropType<String[]>,
    default: [],
  },
  multiSpec: propTypes.bool,
  categoryName: propTypes.string,
  categoryId: propTypes.string,
  // 属性
  attributeList: {
    type: [Array] as PropType<any[]>,
    default: [],
  },
}

export interface Spec {
  id: string
  goodsId: string
  name: string
  values: string[]
  specId: string
}

export interface SingleSpec {
  key: string
  value: string
  specId: string
}

export interface Sku {
  tempId: string
  id: string
  skuCode: string
  price: string
  costPrice: string
  stockList: Stock[]
  saleNumber: number
  specData: SingleSpec[]
  lockStock: number
  weight: number
  picture: string
}

export interface Stock {
  storeId: string
  stock: number
}
